import axios from 'axios'
import Nprogress from 'nprogress'

const instance =  axios.create({
  baseURL: 'http://127.0.0.1:3001/',
  timeout: 3000
})

instance.interceptors.request.use((res) => {
  if(typeof document === 'object') Nprogress.start()
  return res
})
instance.interceptors.response.use((req) => {
  if(typeof document === 'object') Nprogress.done()
  return req
})

// 这里要怎么catch呀
export default async(method, url, data) => {
  let res
  try{
    res = await instance.request({method, url, data})  
  } catch(error) {
    console.log(error.response.data)
    console.log(error.response.status)
    return ''
  }
  return res.data
}
